/* -*-c++-*- */
/* osgGIS - GIS Library for OpenSceneGraph
 * Copyright 2007-2008 Glenn Waldron and Pelican Ventures, Inc.
 * http://osggis.org
 *
 * osgGIS is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>
 */

#ifndef _OSGGIS_WRITE_FEATURES_FILTER_H_
#define _OSGGIS_WRITE_FEATURES_FILTER_H_ 1

#include <osgGIS/FeatureFilter>
#include <osgGIS/GeoShape>
#include <OpenThreads/Mutex>

namespace osgGIS
{
    class FeatureStore;

    /**
     * Filter that writes incoming features to a FeatureStore.
     *
     * This filter will take the incoming feature stream and write each feature
     * to a new FeatureStore. This is useful if you want to save an intermediate
     * state in the middle of a FilterGraph, or if you want to create a derived
     * data source (say by reprojecting source data) and persist it.
     */
    class OSGGIS_EXPORT WriteFeaturesFilter : public FeatureFilter
    {  
        OSGGIS_META_FILTER( WriteFeaturesFilter );   

    public:
        /**
         * Constructs a new feature-writing filter.
         */
        WriteFeaturesFilter();

        /**
         * Copy constructor.
         */
        WriteFeaturesFilter( const WriteFeaturesFilter& rhs );


    public: //properties

        /**
         * Sets the URI of the feature store to which to write the features. The
         * filter will create a new feature store at the URI.
         *
         * @param value
         *      URI at which to create and open the new feature store
         */
        void setOutputURI( const std::string& value );
        
        /**
         * Gets the URI of the feature store to which to write the featues.
         *
         * @return URI at which to create and open the new feature store
         */
        const std::string& getOutputURI() const;


    public:
        virtual void setProperty( const Property& p );
        virtual Properties getProperties() const;

    public:
        virtual FeatureList process( Feature* input, FilterEnv* env );

        virtual ~WriteFeaturesFilter();

    private:
        std::string output_uri;
        osg::ref_ptr<FeatureStore> store;
        OpenThreads::Mutex store_mutex;
    };
}


#endif // _OSGGIS_WRITE_FEATURES_FILTER_H_

